import request from '@/utils/request'
import type { CategoryResponseData, AttrResponseData, Attr } from './type'

enum API {
  //分类接口地址
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2/',
  C3_URL = '/admin/product/getCategory3/',
  //查询三级分类下已有属性和属性值
  ATTR_URL = '/admin/product/attrInfoList/',
  //添加或修改已有属性和属性值
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  //删除某一个已有的属性和属性值
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}
//分类的请求方法
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL)
export const reqC2 = (category1ID: number | string) =>
  request.get<any, CategoryResponseData>(API.C2_URL + category1ID)
export const reqC3 = (category2ID: number | string) =>
  request.get<any, CategoryResponseData>(API.C3_URL + category2ID)
//查询已有属性和属性值的请求方法
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
//添加或修改已有属性和属性值的方法
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)
//删除已有属性和属性值的方法
export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId)
